package com.example.day03_mvp.adapter;

import android.content.Context;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.day03_mvp.R;
import com.example.day03_mvp.bean.WanBean;

import java.util.List;

public class WanAdapter extends RecyclerView.Adapter<WanAdapter.ViewHolder> {
    public WanAdapter(Context context, List<WanBean.DataBean.DatasBean> datas) {
        this.context = context;
        this.datas = datas;
    }

    private Context context;
    private List<WanBean.DataBean.DatasBean> datas;

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        WanBean.DataBean.DatasBean datasBean = datas.get(position);
        RequestOptions requestOptions = new RequestOptions().circleCrop();
        Glide.with(context).load(datasBean.getEnvelopePic()).apply(requestOptions).into(holder.item_iamge);
        holder.item_name.setText(datasBean.getTitle());
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView item_iamge;
        TextView item_name;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            item_iamge=itemView.findViewById(R.id.item_image);
            item_name=itemView.findViewById(R.id.item_name);
        }
    }
}
